package bl.strategy;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.List;
import po.CouponsPo;
import po.DiscountPackagePo;
import po.DiscountPo;
import po.GiftPo;
import po.Po;
import po.SystemLogPo;
import po.商品列表单项po;
import vo.CouponsVo;
import vo.DiscountPackageVo;
import vo.DiscountVo;
import vo.GiftVo;
import vo.Vo;
import blservice.strategy.StrategyBLService;
import dbservice.history.SystemLogDBService;
import dbservice.strategy.StrategyDBService;
public class StrategyBL extends UnicastRemoteObject implements StrategyBLService{
	private static final long serialVersionUID = -5461185386252908160L;

	StrategyDBService strategydb;
    SystemLogDBService log;
    
   public StrategyBL(StrategyDBService strategydb,SystemLogDBService log) throws RemoteException{
	   this.strategydb=strategydb;
	   this.log=log;
   }
   
   
   //vo，po转化
   private GiftPo _po(GiftVo vo){
		GiftPo po=new GiftPo(vo.getFrom(),vo.getTo(),vo.get客户级别(),vo.get总额条件(),vo.getNum(),vo.get商品编号(),vo.get商品名称(),vo.get商品型号());
		return po;
	}
		private DiscountPo _po(DiscountVo vo){
		DiscountPo po=new DiscountPo(vo.getFrom(),vo.getTo(),vo.get客户级别(),vo.get总额条件(),vo.getDiscount()); 
	    return po;
	}
	
	
	private CouponsPo _po(CouponsVo vo){
		CouponsPo po=new CouponsPo(vo.getFrom(),vo.getTo(),vo.get客户级别(),vo.get总额条件(),vo.getNum(),vo.getValue());
		return po;
	}
	
	
	
	
	private DiscountPackagePo _po(DiscountPackageVo vo){
		DiscountPackagePo  po=new DiscountPackagePo();
		po.setFrom(vo.getFrom());
		po.setTo(vo.getTo());
		po.setPrice(vo.getPrice());
		po.setPackage_name(vo.getPackage_name());
		po.setNum(vo.getNum());
		List<商品列表单项po> cm_po_list=new ArrayList<商品列表单项po>();
		for(int i=0;i<vo.getCommoditypackage().size();i++){
			商品列表单项po cm_po=new 商品列表单项po(vo.getCommoditypackage().get(i).get商品编号(),vo.getCommoditypackage().get(i).get商品名称(),vo.getCommoditypackage().get(i).get商品型号(),vo.getCommoditypackage().get(i).get数量(),vo.getCommoditypackage().get(i).get单价(),vo.getCommoditypackage().get(i).get金额(),vo.getCommoditypackage().get(i).get备注());
		    cm_po_list.add(cm_po);
		}
		po.setCommoditypackage(cm_po_list);
	    return po;
	}
	

   
   
   
   
	

	

  
	
	
	
	
	
	
	
	public Vo saveGift(GiftVo gift) {
		Vo m=new Vo();
		Po po=strategydb.add(_po(gift));
		if(po.isSuccessed()){
			m.successed();
			log.add(new SystemLogPo(gift.getOperator(),"制订了","赠品清单"));
		}else{
			m.failed(po.getFailMessage());
		}
		return m;
	}

	
	public Vo saveDiscount(DiscountVo discount) {
		Vo m=new Vo();
		Po po=strategydb.add(_po(discount));
		if(po.isSuccessed()){
			m.successed();
			log.add(new SystemLogPo(discount.getOperator(),"制订了","价格折让"));
		}else{
			m.failed(po.getFailMessage());
		}
		return m;
	}

	
	public Vo saveDiscountPackage(DiscountPackageVo discountpackage) {
		Vo m=new Vo();
		Po po=strategydb.add(_po(discountpackage));
		if(po.isSuccessed()){
			m.successed();
			log.add(new SystemLogPo(discountpackage.getOperator(),"制订了","特价包商品"));
		}else{
			m.failed(po.getFailMessage());
		}
		return m;
	}

	
	public Vo saveCoupons(CouponsVo coupons) {
		Vo m=new Vo();
		Po po=strategydb.add(_po(coupons));
		if(po.isSuccessed()){
			m.successed();
			log.add(new SystemLogPo(coupons.getOperator(),"制订了","代金券"));
		}else{
			m.failed(po.getFailMessage());
		}
		return m;
	}
  
}
